import Cookies from 'js-cookie';

// 增加内嵌值
export const TOKEN_KEY = 'info_inside';
// 设置平台 token
export const setToken = (token, cookieExpires = 1) => {
  Cookies.set(TOKEN_KEY, token, {
    expires: cookieExpires,
  });
};

export const getToken = () => {
  const token = Cookies.get(TOKEN_KEY);
  if (token) return token;
  return null;
};

export const clearToken = () => {
  Cookies.remove(TOKEN_KEY);
};

// 设置设置是管理员
export const setIsAdmin = (value, cookieExpires = 1) => {
  Cookies.set('isAdmin', value, {
    expires: cookieExpires,
  });
};
export const getIsAdmin = () => {
  const value = Cookies.get('isAdmin');
  if (value) return value;
  return null;
};

export const clearIsAdmin = () => {
  Cookies.remove('isAdmin');
};

// 设置用户信息
export const setUserInfo = (value, cookieExpires = 1) => {
  Cookies.set('userInfo', JSON.stringify(value), {
    expires: cookieExpires,
  });
};
export const getUserInfo = () => {
  const value = Cookies.get('userInfo');
  if (value) return value;
  return null;
};
export const clearUserInfo = () => {
  Cookies.remove('userInfo');
}

export const setPersonalCenterMenu = (value, cookieExpires = 1) => {
  Cookies.set('personalCenterMenu', value, {
    expires: cookieExpires,
  });
};
export const getPersonalCenterMenu = () => {
  const value = Cookies.get('personalCenterMenu');
  if (value) return value;
  return null;
};

export const clearPersonalCenterMenu = () => {
  Cookies.remove('personalCenterMenu');
};
